package com.example.factory.api.controller;

import com.example.factory.api.dto.DtoDepartment;
import com.example.factory.api.dto.Response;
import com.example.factory.api.dto.form.DtoDepartmentForm;
import com.example.factory.api.dto.form.DtoQueryDepartmentListForm;
import com.example.factory.api.facade.DepartmentFacade;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Lei Tao
 */
@RestController
@RequestMapping("/admin/department")
public class DepartmentController {

    private final DepartmentFacade departmentFacade;

    public DepartmentController(DepartmentFacade departmentFacade) {
        this.departmentFacade = departmentFacade;
    }

    @PostMapping("/list")
    public Response<List<DtoDepartment>> list(@RequestBody DtoQueryDepartmentListForm dtoQueryDepartmentListForm) {
        return departmentFacade.departmentList(dtoQueryDepartmentListForm);
    }

    @GetMapping("/{departmentGuid}/delete")
    public Response<Void> deleteDepartment(@PathVariable("departmentGuid") String departmentGuid) {
        return departmentFacade.deleteDepartment(departmentGuid);
    }

    @GetMapping("/{departmentGuid}/details")
    public Response<DtoDepartment> retrieveDepartment(@PathVariable("departmentGuid") String departmentGuid) {
        return departmentFacade.retrieveDepartment(departmentGuid);
    }

    @PostMapping("/save")
    public Response<DtoDepartment> saveOrUpdate(@RequestBody DtoDepartmentForm dtoDepartmentForm) {
        return departmentFacade.saveOrUpdateDepartment(dtoDepartmentForm);
    }

}
